import http from '../httpService'
import { RecommendItemListDto } from './dto/recommendItemListDto';
import { RecommendPagedQueryDto } from './dto/recommendPagedQueryDto';

class RecommendService {
    public async getRecommendItemPagedList(input: RecommendPagedQueryDto): Promise<RecommendItemListDto[]> {
        let url_ = '/api/services/app/Recommend/GetRecommendItemPagedListAsync?';

        if (input.keyWords !== undefined) {
            url_ += 'KeyWords=' + encodeURIComponent('' + input.keyWords) + '&';
        }
        if (input.moduleTypeId !== undefined) {
            url_ += 'moduleTypeId=' + encodeURIComponent('' + input.moduleTypeId) + '&';
        }
        if (input.recommendIds !== undefined) {
            input.recommendIds && input.recommendIds.forEach(item => { url_ += 'RecommendIds=' + encodeURIComponent('' + item) + '&'; });
        }
        if (input.sorting !== undefined)
            url_ += 'Sorting=' + encodeURIComponent('' + input.sorting) + '&';
        if (input.skipCount !== undefined)
            url_ += 'SkipCount=' + encodeURIComponent('' + input.skipCount) + '&';
        if (input.maxResultCount !== undefined)
            url_ += 'MaxResultCount=' + encodeURIComponent('' + input.maxResultCount) + '&';
        url_ = url_.replace(/[?&]$/, '');

        let result = await http.get(url_, {})
        return result.data.result.items
    }
}

export default new RecommendService()